﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using MySite.Timer;
using System.Threading;
using MySite.BLL;

namespace MySite
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("VerifyCode.aspx");
            routes.IgnoreRoute("AjaxRequest.aspx");
            routes.IgnoreRoute("*.ashx");

            routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
            );

            routes.MapRoute("NoAction", "{controller}.aspx", new { controller = "home", action = "index", id = "" });//无Action的匹配 
            routes.MapRoute("NoID", "{controller}/{action}.aspx", new { controller = "home", action = "index", id = "" });//无ID的匹配 
            routes.MapRoute("Root", "", new { controller = "home", action = "index", id = "" });//根目录匹配   

        }

        protected void Application_Start()
        {
            SinaWeiBoTimer myWeiBo = new SinaWeiBoTimer();
            myWeiBo.Start();

            BlogcnTimer myBlog = new BlogcnTimer();
            myBlog.Start(3 * 1000, Timeout.Infinite);

            CnBetaTimer myBeta = new CnBetaTimer();
            myBeta.Start(6 * 1000, Timeout.Infinite);

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            this.Application.Add("BeginTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
        }

        protected void Session_Start()
        {
            if (!Application.AllKeys.Contains("BeginTime"))
            {
                this.Application.Add("BeginTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            }
        }
    }
}